home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: nntp.cadence.com!tmccoy
- From: tmccoy@nntp.cadence.com (Timothy McCoy)
- Subject: problem: sun4 and hpux char * difference
- Message-ID: <Dpnpn5.Lo3@Cadence.COM>
- Summary: C code behaves differently for sun4 and hpux
- Keywords: Help
- Sender: news@Cadence.COM
- Organization: Cadence Design System, Inc.
- X-Newsreader: TIN [version 1.2 PL2]
- Date: Wed, 10 Apr 1996 17:23:28 GMT
-
- I have a program that is made for hpux and sun4 users.
- The sun program fails and the hpux version does not.
- The problem stems from a struct definition that includes
- a pointer to a char. Something like:
-
- typedef struct record
- {
- struct rec *first_rec ;
- char *name ;
- } warn_record ;
-
- After space is allocated for the record, typically, the
- user will do something like this:
-
- lrec = (struct record *)calloc((unsigned)1,sizeof(struct record));
- lrec->node_name = (char *) NULL;
-
- The problem is that, on the sun only, if I try to access
- any of the standard string functions on this char * the
- program dies with a segmentation error. e.g.;
-
- (void) strcpy(astring, lrec->node_name ); /* fine on hp */
- /* Segmentation fault (core dumped) on sun4 */
-
- I believe I understand why its dieing on the sun, as
- a null (zero) address can't be read from (really) but
- myself and others thought that it was 'standard' to
- interpret it as zero and (in this example) copy '\0'
- into astring, which is just what the hp does.
-
- Could someone shed some light on this for me?
-
- Additionally, why, Why, WHY does the sun version of
- this:
-
- printf("name='%s'\n", lrec->node_name);
-
- yield this:
-
- name='(null)'
-
- and hp yields a more reasonable:
-
- name=''
-
- ????
-
- Any insight will be appreciated. Please e-mail your responses
- if possible.
-
- TIA;
-
- Tim McCoy
- tmccoy@cadence.com
-
- P.S. I resolved a small portion of the problem witha declaration:
-
- char *CNULL = { "\0" };
-
- and my initialization changed to:
-
- lrec->node_name = CNULL;
-
- (But this is only a small portion of the overriding problem.)
-
- Thanks.
-